module MCDF(
	//global signal
	input				clk_i,
	input				rst_n_i,
	//register command signal
	input				cmd_sel_i,
	input				cmd_en_i,
	input				cmd_wr_i,
	input	[7:0]		cmd_addr_i,
	input	[31:0]		cmd_data_in_i,
	output	[31:0]		cmd_data_out_o,
	//slave_fifo signal
	input				ch0_valid_i,
	input	[31:0]		ch0_data_i,
	output				ch0_ready_o,
	
	input				ch1_valid_i,
	input	[31:0]		ch1_data_i,
	output				ch1_ready_o,
	
	input				ch2_valid_i,
	input	[31:0]		ch2_data_i,
	output				ch2_ready_o,
	//formator signal
	output				fmt_end_o,
	output	[31:0]		fmt_data_o,
	output				fmt_start_o,
	input				fmt_grant_i,
	output				fmt_req_o,
	output	[5:0]		fmt_length_o
	);
	
	//register to slave_fifo
	wire				slv0_en_s;
	wire				slv1_en_s;
	wire				slv2_en_s;
	wire	[5:0]		slv0_margin_s;
	wire	[5:0]		slv1_margin_s;
	wire	[5:0]		slv2_margin_s;
	
	//register to arbiter
	wire	[5:0]		slv0_pkglen_s;
	wire	[5:0]		slv1_pkglen_s;
	wire	[5:0]		slv2_pkglen_s;
	wire	[1:0]		slv0_pri_s;
	wire	[1:0]		slv1_pri_s;
	wire	[1:0]		slv2_pri_s;

	//slave_fifo to arbiter
	wire	[31:0]		slv0_data_s;
	wire	[31:0]		slv1_data_s;
	wire	[31:0]		slv2_data_s;
	
	wire				slv0_req_s;
	wire				slv1_req_s;
	wire				slv2_req_s;
	
	wire				slv0_valid_s;
	wire				slv1_valid_s;
	wire				slv2_valid_s;
	
	wire				a2s0_ack_s;
	wire				a2s1_ack_s;
	wire				a2s2_ack_s;
	
	//formater to arbiter
	wire				f2a_ack_s;
	wire				a2f_val_s;
	wire				f2a_id_req_s;
	wire	[31:0]		a2f_data_s;
	wire	[1:0]		a2f_id_s;
	wire	[2:0]		pkglen_sel_s;
	
	registers reg_inst(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		.cmd_en_i(cmd_en_i),
		.cmd_sel_i(cmd_sel_i),
		.cmd_wr_i(.cmd_wr_i),
		.cmd_addr_i(cmd_addr_i),
		.cmd_data_in_i(cmd_data_in_i),
		.cmd_data_out_o(cmd_data_out_o),
		.slv0_en_o(slv0_en_s),
		.slv1_en_o(slv1_en_s),
		.slv2_en_o(slv2_en_s),
		.slv0_margin_i(slv0_margin_s),
		.slv1_margin_i(slv1_margin_s),
		.slv2_margin_i(slv2_margin_s),
		.slv0_pkglen_o(slv0_pkglen_s),
		.slv1_pkglen_o(slv1_pkglen_s),
		.slv2_pkglen_o(slv2_pkglen_s),
		.slv0_pri_o(slv0_pri_s),
		.slv1_pri_o(slv1_pri_s),
		.slv2_pri_o(slv2_pri_S)
	);
	
	slave_fifo slv0(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		.chx_data_i(ch0_data_i),
		.chx_ready_o(ch0_ready_o),
		.chx_valid_i(ch0_valid_i),
		.slvx_en_i(slv0_en_s),
		.slvx_margin_o(slv0_margin_s),
		.slvx_data_o(slv0_data_s),
		.slvx_valid_i(slv0_valid_s),
		.slvx_req_i(slv0_req_s),
		.slvx_read_ack_i(a2s0_ack_s)
	);
	
	slave_fifo slv1(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		.chx_data_i(ch1_data_i),
		.chx_ready_o(ch1_ready_o),
		.chx_valid_i(ch1_valid_i),
		.slvx_en_i(slv1_en_s),
		.slvx_margin_o(slv1_margin_s),
		.slvx_data_o(slv1_data_s),
		.slvx_valid_i(slv1_valid_s),
		.slvx_req_i(slv1_req_s),
		.slvx_read_ack_i(a2s1_ack_s)
	);
	
	slave_fifo slv2(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		.chx_data_i(ch2_data_i),
		.chx_ready_o(ch2_ready_o),
		.chx_valid_i(ch2_valid_i),
		.slvx_en_i(slv2_en_s),
		.slvx_margin_o(slv2_margin_s),
		.slvx_data_o(slv2_data_s),
		.slvx_valid_i(slv2_valid_s),
		.slvx_req_i(slv2_req_s),
		.slvx_read_ack_i(a2s2_ack_s)
	);
	
	arbiter arb1(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		
		//connect with registers
		.slv0_pri_i(slv0_pri_s),
		.slv1_pri_i(slv1_pri_s),
		.slv2_pri_i(slv2_pri_s),
		
		//connect with slave_fifo
		.slv0_data_i(slv0_data_s),
		.slv1_data_i(slv1_data_s),
		.slv2_data_i(slv2_data_s),
		.slv0_req_o(slv0_req_s),
		.slv1_req_o(slv1_req_s),
		.slv2_req_o(slv2_req_s),
		.slv0_valid_o(slv0_valid_s),
		.slv1_valid_o(slv1_valid_s),
		.slv2_valid_o(slv2_valid_s),
		.slv0_pkglen_i(slv0_pkglen_s),
		.slv1_pkglen_i(slv1_pkglen_s),
		.slv2_pkglen_i(slv2_pkglen_s),
		.a2s0_ack_o(a2s0_ack_s),
		.a2s1_ack_o(a2s1_ack_s),
		.a2s2_ack_o(a2s2_ack_s),
		
		//connect witsh formater
		.a2f_pkglen_sel_o(pkglen_sel_s),
		.f2a_ack_i(f2a_ack_s),
		.f2a_id_req_i(f2a_id_req_s),
		.a2f_val_o(a2f_val_s),
		.a2f_id_o(a2f_id_s),
		.a2f_data_o(a2f_data_s)
	);
	
	formater formater_inst(
		.clk_i(clk_i),
		.rst_n_i(rst_n_i),
		.a2f_val_i(a2f_val_s),
		.pkglen_sel_i(pkglen_sel_s)
		.a2f_id_i(a2f_id_s),
		.a2f_data_i(a2f_data_s),
		.f2a_ack_o(f2a_ack_s),
		.fmt_id_req_o(f2a_id_req_s),
		.fmt_chid_o(fmt_chid_o),
		.fmt_end_o(fmt_end_o),
		.fmt_data_o(fmt_data_o),
		.fmt_start_o(fmt_start_o),
		.fmt_grant_i(fmt_grant_i),
		.fmt_req_o(fmt_req_o),
		.fmt_length_o(fmt_length_o)
	);

endmodule